home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
mg2a_src.zip
/
SYS
/
AMIGA
/
TTYIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-08-23
|
26KB
|
989 lines
/*
* Name: MG 2a
* Amiga terminal window I/O, with all kinds o' trimmings.
* This module is 'way too big.
* Last Edit: 01-Dec-87 mic@emx.cc.utexas.edu
* Created: 21-Apr-86 mic@emx.cc.utexas.edu
*/
/*
* Lots of includes.
*/
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/tasks.h>
#include <exec/ports.h>
#include <exec/io.h>
#include <devices/console.h>
#include <devices/inputevent.h>
#include <libraries/dos.h>
#include <graphics/clip.h>
#include <graphics/view.h>
#include <graphics/rastport.h>
#include <graphics/layers.h>
#include <graphics/text.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <libraries/diskfont.h>
#undef TRUE /* avoid redefinition messages */
#undef FALSE
#include "def.h" /* includes sysdef.h and ttydef.h */
/*
* External Amiga functions.
*/
extern LONG AbortIO();
extern LONG CloseDevice();
extern LONG CloseLibrary();
extern LONG CloseWindow();
extern struct MsgPort *CreatePort();
extern struct IOStdReq *CreateStdIO();
extern LONG DeletePort();
extern LONG DeleteStdIO();
extern struct IntuiMessage *GetMsg();
#ifndef V11
extern LONG GetScreenData();
#endif
extern int OpenConsole();
extern char *OpenLibrary();
extern struct Window *OpenWindow();
extern struct TextFont *OpenDiskFont();
extern LONG RectFill();
extern LONG ReplyMsg();
extern LONG RawKeyConvert();
extern LONG SetAPen();
extern LONG SetDrMd();
extern LONG Wait();
#ifdef DO_MENU
extern LONG ClearMenuStrip(); /* menu functions */
extern struct Menu *InitEmacsMenu();
extern struct MenuItem *ItemAddress();
extern LONG SetMenuStrip();
#endif
#ifdef MANX
extern int Enable_Abort; /* Do NOT allow abort! */
#endif
/*
* External MG functions and variables
*/
extern int quit(); /* Defined by "main.c" */
extern char version[]; /* Version information */
extern int ttrow; /* Current cursor row */
extern int use_metakey; /* Do meta characters? */
/*
* Non-int internal functions. P?() is used to conditionally indicate
* ANSI-style prototype arguments for compilers (i.e. Lattice) that
* support them.
*/
#ifdef LATTICE
#define P1(a) a,
#define P2(a,b) a,b
#define P3(a,b,c) a,b,c
#else
#define P1(a)
#define P2(a,b)
#define P3(a,b,c)
#endif
VOID panic(P1(char *));
VOID setttysize();
VOID ttclose();
VOID ttflush();
VOID ttnflush(P1(int));
VOID ttputc(P1(unsigned char));
static VOID cleanup();
static VOID firstwin();
static VOID qkey(P1(KCHAR));
#ifdef DO_MENU
static VOID qmenu(P1(USHORT));
#endif
#ifdef MOUSE
static VOID qmouse(P3(SHORT, SHORT, USHORT));
#endif
static VOID ttreopen(P1(int)) ;
static VOID setmaxima() ;
static struct Screen *wbscreen();
/*
* Library bases (used by glue libraries)
*/
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
ULONG DiskfontBase;
/*
* Intuition window and menu variables. MG gets used a lot, because it
* gets reconfigured on the fly for the amiga-set-font and toggle-border
* operations.
*/
#define WINDOWGADGETS (WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE)
#define WINDOWFLAGS (WINDOWGADGETS | ACTIVATE)
struct NewWindow MG = {
0, 0, /* start position */
0, 0, /* width, height (set by ttopen)*/
0, 1, /* detail pen, block pen */
#ifdef DO_MENU
MENUPICK | /* If menu is used */
#endif
#ifdef MOUSE
MOUSEBUTTONS | /* If mouse is used */
#endif
INTUITICKS | RAWKEY |
CLOSEWINDOW | NEWSIZE, /* IDCMP flags */
0, /* window flags (set by ttopen) */
NULL, /* pointer to first user gadget */
NULL, /* pointer to user checkmark */
NULL, /* title (filled in later) */
NULL, /* pointer to screen (none) */
NULL, /* pointer to superbitmap */
220,40, /* minimum size (small!) */
0, 0, /* maximum size (set by ttopen) */
WBENCHSCREEN /* screen in which to open */
};
static short borderless = TRUE; /* Flag for borderless window */
static short toggle_zooms = TRUE; /* Does toggling border zoom? */
static int last_top, last_left, last_height, last_width;
struct Window *EmW = NULL; /* Our window */
struct Screen *EmS = NULL; /* Our screen (usually WB) */
short toggling = FALSE; /* Prevent menu wiping */
#ifndef V11
struct Screen WBInfo; /* Info about the WB screen */
#endif
struct TextFont *EmFont = NULL; /* Our font (usually TOPAZ_xx) */
#ifdef DO_MENU
static struct Menu *EmacsMenu = NULL; /* Our menu */
#endif
static ULONG class; /* Intuition event */
static USHORT code, /* information */
qualifier;
static APTR address;
static SHORT x, y;
static LONG intuitionMsgBit; /* Signal bit */
#define INTUITION_MESSAGE ((LONG) (1L << intuitionMsgBit))
/* * * * * * * * * * * * * console I/O * * * * * * * * * * * * * * * * */
#define CSI 0x9b /* Command Sequence Introducer */
#define NOBUF 512 /* About 1/4 screen */
#define NIBUF 256 /* Input buffer */
static KCHAR ibuf[NIBUF]; /* keyboard input buffer */
static int ibufo, nibuf; /* head, # of bytes in ibuf */
#ifndef PROMPTWAIT
#define PROMPTWAIT 20 /* ticks to wait before timeout */
#endif
static LONG tickcount; /* # intuiticks since last char */
static struct MsgPort *conWritePort = NULL; /* I/O ports */
static struct IOStdReq *conWriteMsg = NULL; /* I/O messages */
struct Device *ConsoleDevice; /* used by RawKeyConvert*/
static unsigned char outbuf[NOBUF+7]; /* output buffer */
static unsigned char *obuf; /* first output char */
int nobuf; /* # of bytes in above */
int nrow; /* Terminal size, rows. */
int ncol; /* Terminal size, cols. */
/* * * * * * * * * functions to open/reopen the window * * * * * * * * * */
/*
* Open up the virtual terminal MG communicates with. Set up the window,
* console, and menu strip.
*/
ttopen()
{
#ifdef MANX
Enable_Abort = 0; /* Disable ^C */
#endif
/* firstwin() is only called the very first time we open the window */
if (toggling == FALSE)
firstwin();
/* Set the window size, set the flags and title, and open it */
setmaxima();
MG.Flags = WINDOWFLAGS;
MG.Flags |= borderless ? BORDERLESS : WINDOWSIZING;
MG.Title = (UBYTE *) &version[0];
if ((EmW = OpenWindow(&MG)) == NULL)
cleanup();
SetFont(EmW->RPort, EmFont);
/* Once the window is created, get the Intuition signal bit, set up
* the menu, and tell the virtual terminal how big it is.
*/
setttysize();
intuitionMsgBit = EmW->UserPort->mp_SigBit;
#ifdef DO_MENU
if (toggling == FALSE)
EmacsMenu = InitEmacsMenu(EmW);
if (EmacsMenu == NULL)
cleanup();
SetMenuStrip(EmW, EmacsMenu);
#endif
/* Attach a console device (purely for output now) to our window
*/
if ((conWritePort = CreatePort("Emacs.con.write", 0L)) == NULL)
cleanup();
if ((conWriteMsg = CreateStdIO(conWritePort)) == NULL)
cleanup();
if (OpenConsole(conWriteMsg,NULL,EmW) != 0)
cleanup();
ConsoleDevice = conWriteMsg->io_Device;
nibuf = ibufo = 0;
return (0);
}
/*
* Set up the initial state of the window. Opens up libraries, decides how
* big the initial window should be, and whether it should be borderless.
*/
static VOID firstwin()
{
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L);
if (GfxBase == NULL) /* Graphics lib */
cleanup();
IntuitionBase = (struct IntuitionBase *) /* Intuition */
OpenLibrary("intuition.library", 0L);
if (IntuitionBase == NULL)
cleanup();
DiskfontBase = (ULONG) OpenLibrary("diskfont.library", 0L);
if (DiskfontBase == NULL)
cleanup();
/* Get our screen and font, then figure out if we can go borderless
*/
if ((EmS = wbscreen()) == NULL)
cleanup();
EmFont = OpenDiskFont(EmS->Font);
if ((EmS->Width >= ((INIT_COLS * EmFont->tf_XSize) + LR_BORDER)) &&
(EmS->Height >= ((INIT_ROWS * EmFont->tf_YSize) + TB_BORDER)))
borderless = FALSE;
/* Set the size of the initial window and fake the last one
*/
last_wid